<?php
namespace BC\Wallet\Bitcoin;

use BC\User\Grant\DB\GrantDB as DB;
use CPath\Data\Schema\IReadableSchema;
use CPath\Data\Schema\PDO\AbstractPDOPrimaryKeyTable as AbstractBase;
use CPath\Data\Schema\TableSchema;

/**
 * Class BitcoinAddressLookupTable
 * @table bitcoin_address_lookup
 * @satoshi BTC=x/100000000
 * @method BitcoinAddressLookup insertOrUpdate($address, Array $insertData) insert or update a BitcoinAddressLookup instance
 * @method BitcoinAddressLookup insertAndFetch(Array $insertData) insert and fetch a BitcoinAddressLookup instance
 * @method BitcoinAddressLookup fetch($whereColumn, $whereValue=null, $compare='=?', $selectColumns=null) fetch a BitcoinAddressLookup instance
 * @method BitcoinAddressLookup fetchOne($whereColumn, $whereValue=null, $compare='=?', $selectColumns=null) fetch a single BitcoinAddressLookup
 * @method BitcoinAddressLookup[] fetchAll($whereColumn, $whereValue=null, $compare='=?', $selectColumns=null) fetch an array of BitcoinAddressLookup[]
 */
class BitcoinAddressLookupTable extends AbstractBase implements IReadableSchema {
	const TABLE_NAME = 'bitcoin_address_lookup';
	const FETCH_CLASS = 'BC\\Wallet\\Bitcoin\\BitcoinAddressLookup';
	const SELECT_COLUMNS = 'address, last_check, balance, received_by_address, sent_by_address';
	const UPDATE_COLUMNS = 'last_check, balance, received_by_address, sent_by_address';
	const INSERT_COLUMNS = 'last_check, balance, received_by_address, sent_by_address';
	const PRIMARY_COLUMN = 'address';
	/**

	 * @column PRIMARY KEY
	 * @select
	 */
	const COLUMN_ADDRESS = 'address';
	/**

	 * @column INTEGER
	 * @select
	 * @insert
	 * @update
	 */
	const COLUMN_LAST_CHECK = 'last_check';
	/**

	 * @column INTEGER
	 * @select
	 * @insert
	 * @update
	 */
	const COLUMN_BALANCE = 'balance';
	/**

	 * @column INTEGER
	 * @select
	 * @insert
	 * @update
	 */
	const COLUMN_RECEIVED_BY_ADDRESS = 'received_by_address';
	/**

	 * @column INTEGER
	 * @select
	 * @insert
	 * @update
	 */
	const COLUMN_SENT_BY_ADDRESS = 'sent_by_address';

	function insertRow($last_check = null, $balance = null, $received_by_address = null, $sent_by_address = null) { 
		return $this->insert(get_defined_vars());
	}

	function getSchema() { return new TableSchema('BC\\Wallet\\Bitcoin\\BitcoinAddressLookup'); }

	private $mDB = null;
	function getDatabase() { return $this->mDB ?: $this->mDB = new DB(); }
}